package com.kaifamiao.handling;

/**
 * 1、使用自定义异常类型
 * 2、异常转译
 */
public class Monkey {

    public int divide(int dividend, int divisor) throws MathException {
        try {
            System.out.printf( "求 %d 除以 %d 的商\n" , dividend, divisor );
            int shang = dividend / divisor;
            System.out.printf("商: %d\n" , shang );
            return shang;
        }
        // 可能会捕获到 算术异常(ArithmeticException)
        catch ( ArithmeticException cause ) {
            // 根据捕获到的异常创建新的异常对象
            MathException me = new MathException("除数不能为零", cause );
            // 抛出新的异常对象
            throw me;
        }
    }

    public static void main(String[] args) throws Throwable {
        Monkey m = new Monkey();
        int result = m.divide( 100 , 0 );
        System.out.println( result );
    }

}
